# -*- coding: utf-8 -*-
import numpy
from matplotlib import pyplot, cm
from mpl_toolkits.mplot3d import Axes3D
from ..widgets import widget

class surface_3d_figure(widget):
	'''
	生成海拔3d图
	'''
	def _from_original_index_to_vectorise_func(self,original_index):
		index_list=original_index.tolist()
		supplier_name_to_num_index=lambda x: (index_list.index(x))
		vectorised_elementwise_func=numpy.vectorize(supplier_name_to_num_index)
		return vectorised_elementwise_func,index_list

	def __init__(self,data_set):
		super(surface_3d_figure, self).__init__()
		self._vectorised_index_to_num_index,self._index_list=self._from_original_index_to_vectorise_func(data_set.axes[0].values)
		self._vectorised_column_to_num_column,self._column_list=self._from_original_index_to_vectorise_func(data_set.axes[1].values)
		test_supplier_index=self._vectorised_index_to_num_index(data_set.axes[0].values)
		test_channel_index=self._vectorised_column_to_num_column(data_set.axes[1].values)

		X, Y=numpy.meshgrid(test_supplier_index, test_channel_index)
		Z=data_set.T.values

		current_figure=pyplot.figure()
		ax=Axes3D(current_figure)

		surf=ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='jet', linewidth=0, antialiased=False)
		#current_figure.colorbar(surf, shrink=1, aspect=10)

		axes_3d=current_figure.axes[0]
		axes_3d.set_xticks(test_supplier_index,minor=False)#设置x轴刻度
		axes_3d.set_yticks(test_channel_index,minor=False)#设置y轴刻度

		axes_3d.set_xticklabels(self._index_list)#用原先的标签替换x轴标签
		axes_3d.set_yticklabels(self._column_list)#用原先的标签替换y轴标签
		current_figure.tight_layout()

		pass
	pass
